﻿using ProjectFootball.MVC.Models.EntityFramework.Entities;
using System;
using System.Security.Principal;

namespace ProjectFootball.MVC.Areas.PersonArea.Models
{
    public static class _PersonDataModelExtensions
    {
        public static Person CreateNew(this PersonDataModel personDataModel, IPrincipal user)
        {
            personDataModel.ApprovalGuid = Guid.NewGuid();

            return personDataModel.CreateUnapproved(user);
        }

        public static Person CreateUnapproved(this PersonDataModel personDataModel, IPrincipal user)
        {
            return new Person()
            {
                Pk = Guid.NewGuid(),
                ApprovalGuid = personDataModel.ApprovalGuid,
                Forenames = personDataModel.Forenames,
                Surname = personDataModel.Surname,
                Dob = personDataModel.Dob,
                CountryGuid = personDataModel.CountryGuid,
                ActiveFrom = personDataModel.ActiveFrom,
                ActiveTo = personDataModel.ActiveTo,
                IsApproved = user.IsApprover(),
                AuditUserId = user.GetUserId(),
                AuditTimestamp = DateTime.Now
            };
        }
    }
}